package com.example.yaun0608;

import android.content.ContentValues;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText et_name;
    private EditText et_author;
    private Button butt_sc;
    private Button butt_ck;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        et_name = (EditText) findViewById(R.id.et_name);
        et_author = (EditText) findViewById(R.id.et_author);
        butt_sc = (Button) findViewById(R.id.butt_sc);
        butt_ck = (Button) findViewById(R.id.butt_ck);

        butt_sc.setOnClickListener(this);
        butt_ck.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.butt_sc:
                String insert = "content://com.example.yuan0608.MyProvider/books_insert";
                Uri uri2 = Uri.parse(insert);
                ContentValues values = new ContentValues();
                String name = et_name.getText().toString().trim();
                String author = et_author.getText().toString().trim();
                values.put("bookname", name);
                values.put("author", author);
                Uri insert1 = getContentResolver().insert(uri2, values);
                Toast.makeText(this, "", Toast.LENGTH_SHORT).show();
                break;
            case R.id.butt_ck:
                Intent intent = new Intent(this, Main2Activity.class);
                startActivity(intent);
                break;
        }
    }
}
